<script lang="ts">
import Tabulation from "../assembling_plugins/Tabulation.svelte";
import {message} from 'antd';
import {querySysLog, removeSysLog} from './service';

/**
 *  删除节点
 * @param selectedRows
 * : TableListItem[]
 */
const handleRemove = async (selectedRows) => {
    const hide = message.loading('正在删除');
    if (!selectedRows) return true;
    try {
        await removeSysLog({
            ids: selectedRows.map((row) => row.id),
        });
        hide();
        message.success('删除成功，即将刷新');
        return true;
    } catch (error) {
        hide();
        message.error('删除失败，请重试');
        return false;
    }
};

const columns = [
    {
        title: '用户名',
        dataIndex: 'userName',
    },
    {
        title: 'IP地址',
        dataIndex: 'ip',
    },
    {
        title: '状态',
        dataIndex: 'status',
        hideInSearch: true,
    },
    {
        title: '创建人',
        dataIndex: 'createBy',
        hideInSearch: true,
    },
    {
        title: '创建时间',
        dataIndex: 'createTime',
        sorter: true,
        hideInSearch: true,
    }
];

const ids = {
    pageSize: 1,
    current: 10
};
const datalistRs = querySysLog(ids);


</script>
<svelte:head>
    <title>系统操作日志</title>
    <meta name="description" content="系统操作记录" />
</svelte:head>

<Tabulation datalist="{datalistRs}" column="{columns}" on:helloparent={(e) => {
    const id = {id:e.detail};
    handleRemove(id);
}} />
